jQuery.validator.addMethod("isZipCode", function(value, element) {
	var tel = /^[0-9]{6}$/;
	return this.optional(element) || (tel.test(value));
}, "请正确填写您的邮政编码");

jQuery.validator.addMethod("isQQ", function(value, element) {
	var tel = /^[1-9]\d{4,10}$/;
	return this.optional(element) || (tel.test(value));
}, "请正确填写您的QQ号码");

jQuery.validator.addMethod("isMobile", function(value, element) {
	var tel = /^1(3|5|4|7|8)\d{9}$|^[1,5,6,9](?:\d{7}|\d{8}|\d{12})$/;
	return this.optional(element) || (tel.test(value));
}, "请正确填写您的手机号码");

jQuery.validator.addMethod("isCheckAccount", function(value, element) {
	return this.optional(element) || /^1(3|5|4|7|8)\d{9}$/.test(value) || (/^[a-z0-9][\w]{5,15}$/i.test(value)&&!/^\d*$/.test(value)) || /^[\w-]+@[\w-]+(?:\.[\w-]+)?\.[\w]{1,5}$/i.test(value);
}, "手机、邮箱、6~16个英文字符与数字组成");

jQuery.validator.addMethod("isIdCard", function(value, element) {
	//var tel = /^\d{15}$|^\d{18}$|^\d{17}(\d|X|x)$/;
	return this.optional(element) || parseIdCard(value);
}, "请正确填写您的身份证号码");

jQuery.validator.addMethod("isZNum", function(value, element) {
	var tel = /^\d+$|^\d+\.\d{1,2}$/;
	return this.optional(element) || (tel.test(value));
}, "请输入整数或最多带2位小数的数字");

jQuery.validator.addMethod("checkPassword", function(value, element) {
	var tel = /^[0-9A-Za-z|_|\-|+|*|!|@|#|$|%|^|&|(|)|~]*$/;
	return this.optional(element) || (tel.test(value)) && !/^\d*$/.test(value);
}, "6~20个字符，密码不能为纯数字或非法字符");

jQuery.validator.addMethod("isCode", function(value, element) {
	var tel = /^[0-9]{6}$/;
	return this.optional(element) || (tel.test(value));
}, "请正确填写验证码");

jQuery.validator.addMethod("isBankid", function(value, element) {
	var tel = /^\d{16,20}$/;
	return this.optional(element) || (tel.test(value));
}, "请输入正确的银行卡号");

jQuery.validator.addMethod("isSelectBank", function(value, element) {
	var str = /-----请选择收款银行的名称-----/;
	return this.optional(element) || (!str.test(value));
}, "请选择收款银行的名称");

jQuery.validator.addMethod("checkRealname", function(value, element) {
	var tel = /^([\u0391-\uFFE5]|[a-zA-Z]|\.|\s){1,20}$/;
	return this.optional(element) || (tel.test(value));
}, "姓名由1-20个字符中英文组成");

jQuery.validator.addMethod("isPhone", function(value, element) {
	var tel = /^\d{3,4}\-\d{7,8}(-\d{1,5})?$|^[1][34578][0-9]{9}$/;
	return this.optional(element) || (tel.test(value));
}, "请填写正确的电话号码");

jQuery.validator.addMethod("nequalTo", function(value, element, param) {
	return value != $(param).val();
}, "两个值不能一样");

/*所在地区选到最后一项*/
jQuery.validator.addMethod("countSelect", function() {
    var edit_region=$('.edit_region');
    var go=true;
    if(edit_region.length<=0 || edit_region.css('display')=='none'){
      var lens=$('#region').children('select').length;
      if(lens<3){
          go=false;
      }else{
        if($('#region').children('select').eq(2).val() == '请选择...'){
          go=false;
        }
      }
    }
    return go;
}, "请选择所在地区到最后一项");

  /* 检验身份证号码的函数 */
function parseIdCard(id_card){
  var i;
  var return_str = "";
  var reg18 = /^[0-9]{17}([0-9]|[X]|[x])$/;
  var reg15 = /^[0-9]{14}([0-9]|[X]|[x])$/;
  if(reg15.test(id_card))
  {
    //如果是15位身份证号先转化成18位
    var last_three=Number(id_card.substr(12,3));
    if(last_three==996||last_three==997||last_three==998||last_three==999)
      id_card=id_card.substr(0,6)+"19"+id_card.substr(6,9);
    else
      id_card=id_card.substr(0,6)+"18"+id_card.substr(6,9);
    var factor=new Array(7,9,10,5,8,4,21,6,37,9,10,5,8,4,2);
    var verify_number_list=Array("1","0","X","9","8","7","6","5","4","3","2");

    var checknum=0;
    for(i=0;i<id_card.length;i++)
      checknum+=id_card.substr(i,1)*factor[i];
    var mod=checknum%11;
    var verify_number=verify_number_list[mod];
    if(verify_number==null)
      return false;
    id_card=id_card+verify_number;
  }
  else if(!reg18.test(id_card))
  {
    return false;
  }

  //匹配行政区
  var province_arr=new Array();
  province_arr[11]="北京市";
  province_arr[12]="天津市";
  province_arr[13]="河北省";
  province_arr[14]="山西省";
  province_arr[15]="内蒙古自治区";
  province_arr[21]="辽宁省";
  province_arr[22]="吉林省";
  province_arr[23]="黑龙江省";
  province_arr[31]="上海市";
  province_arr[32]="江苏省";
  province_arr[33]="浙江省";
  province_arr[34]="安徽省";
  province_arr[35]="福建省";
  province_arr[36]="江西省";
  province_arr[37]="山东省";
  province_arr[41]="河南省";
  province_arr[42]="湖北省";
  province_arr[43]="湖南省";
  province_arr[44]="广东省";
  province_arr[45]="广西壮族自治区";
  province_arr[46]="海南省";
  province_arr[50]="重庆市";
  province_arr[51]="四川省";
  province_arr[52]="贵州省";
  province_arr[53]="云南省";
  province_arr[54]="西藏自治区";
  province_arr[61]="陕西省";
  province_arr[62]="甘肃省";
  province_arr[63]="青海省";
  province_arr[64]="宁夏回族自治区";
  province_arr[65]="新疆维吾尔自治区";
  province_arr[71]="台湾省";
  province_arr[81]="香港特别行政区";
  province_arr[82]="澳门特别行政区";
  province_arr[90]="国外";
  province_arr[91]="国外";
  province_arr[92]="国外";

  var province_str=id_card.substr(0,2);
  if(province_arr[province_str]==null)
    return false;

  //出生日期
  var birthday_year=id_card.substr(6,4);
  var birthday_month=id_card.substr(10,2);
  if(Number(birthday_month)<1||Number(birthday_month)>12)
    return false;

  var birthday_day=id_card.substr(12,2);
  if(Number(birthday_day)<1||Number(birthday_day)>31)
    return false;
  var nowdate = new Date();
  if((nowdate.getFullYear()-birthday_year)<18)
    return false;
  //验证位
  var iSum=0;
  for(i=17;i>=0;i--)
  {
    if(id_card.charAt(17-i)=='x'||id_card.charAt(17-i)=='X')
      iSum+=(Math.pow(2,i)%11)*10;
    else
      iSum+=(Math.pow(2,i)%11)*parseInt(id_card.charAt(17-i),11);
  }

  if(iSum%11!=1)
    return false;

  return true;

}  